package api_.collectionTest;

import java.util.ArrayList;

public class ArrayListDemo
{
    public static void main(String[] args)
    {
        ArrayList<String> arrayList = new ArrayList<>();
        // 增
        arrayList.add("apple");
        arrayList.add("banana");
        arrayList.add("watermalen");
        arrayList.add(1,"cherry");
        if(!arrayList.isEmpty())
        {
            System.out.println(arrayList.size());
        }
        // search
        String s = arrayList.get(1);
        System.out.println("arrayList[1] = " + s  );

        if(arrayList.contains("watermalen"))
        {
            System.out.println("arraylist contains watermalen");
        }
        // alert
        arrayList.set(0, "applE");
        System.out.println(arrayList);

        // delete
        arrayList.remove(1);
        arrayList.remove("applE");  //
        arrayList.clear();

        System.out.println("--------------------------------------------");
        SimpleArrayList simpleArrayList = new SimpleArrayList();
        simpleArrayList.add(1);
        simpleArrayList.add("2");
        simpleArrayList.add(3);
        simpleArrayList.add("4");
        System.out.println(simpleArrayList);
        simpleArrayList.remove(1);
        System.out.println(simpleArrayList);
        System.out.println(simpleArrayList.size());
    }
}
